<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DataType class</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="../../javascript/DataType.class.js"></script>
<script type="text/javascript" src="../../javascript/global.js"></script>
<script type="text/javascript" src="../../javascript/util.js"></script>
<script type="text/javascript" src="../../data_sample/mockup_data.js"></script>
<script type="text/javascript">
flags = {
      "ONEWAY_MESSAGE_FLAG" : 1,
      "TWOWAY_MESSAGE_FLAG" : 2,
      "MY_POST_FLAG" : 4,
      "FRIEND_POST_FLAG" : 8,
      "MY_COMMENT_ON_STATUS_FLAG" : 16,
      "MY_COMMENT_ON_LINK_FLAG" : 32,
      "MY_COMMENT_ON_NOTE_FLAG" : 64,
      "MY_COMMENT_ON_PHOTO_FLAG" : 128,
      "FRIEND_COMMENT_ON_STATUS_FLAG" : 256,
      "FRIEND_COMMENT_ON_LINK_FLAG" : 512,
      "FRIEND_COMMENT_ON_NOTE_FLAG" : 1024,
      "FRIEND_COMMENT_ON_PHOTO_FLAG" : 2048,
      "MY_LIKE_ON_STATUS_FLAG" : 4096,
      "MY_LIKE_ON_LINK_FLAG" : 8192,
      "MY_LIKE_ON_NOTE_FLAG" : 16384,
      "MY_LIKE_ON_PHOTO_FLAG" : 32768,
      "FRIEND_LIKE_ON_STATUS_FLAG" : 65536,
      "FRIEND_LIKE_ON_LINK_FLAG" : 131072,
      "FRIEND_LIKE_ON_NOTE_FLAG" : 262144,
      "FRIEND_LIKE_ON_PHOTO_FLAG" : 524288
  };
  
module("Data concatenation Test Suite");

test("bitwise operation",function(){
	var a = 1;
	var b = 2;
	var c = 4;
	
	equal(a | b, 3);
	equal(a | c, 5);
	equal(a|b|c, 7);
    equal((a+b) | (b+c), 7);
	
    var mask = 2;
    equal(7 ^ mask, 5);	
	
	var input = 15; //1111
	var mask = 10;  //1010
	
	trace2(input & (~ mask));
	
	equal(32 & (~524288), 32);
	equal(7 & (~12), 3);
});

test("traversing in an object", function(){
	var obj = {
		"a": 1,
		"b": 2,
		"c": 3
	};
	
	for(var i in obj){
		trace2(i);
		trace2(obj[i]);
	}
});

test("concat test", function(){

    equal(sample_friend_post_data.mode, 8);
	equal(Object.size(sample_friend_post_data.data), 2);
	trace2(sample_friend_post_data);
	trace2(sample_my_post_data);
	
	equal(sample_my_post_data.mode, 4);
	equal(Object.size(sample_my_post_data.data), 2);
	
	var data = concat(sample_friend_post_data, sample_my_post_data);
	
	equal(data.mode, 12);
	equal(Object.size(data.data), 2);
	
	for(var id in data.data){
		notEqual(data.data[id][flags.MY_POST_FLAG], undefined, "MY_POST_FLAG must not be undefined");
		notEqual(data.data[id][flags.FRIEND_POST_FLAG], undefined, "FRIEND_POST_FLAG must not be undefined");
	}
	
	equal(data.data["100000416787478"][flags.MY_POST_FLAG], 1);
	equal(data.data["100000416787478"][flags.FRIEND_POST_FLAG], 1);
	equal(data.data["100000525262538"][flags.MY_POST_FLAG], 2);
    equal(data.data["100000525262538"][flags.FRIEND_POST_FLAG], 2);

    
	
});

test("concat against data with errors test", function(){
	try {
		var data = concat(sample_post_data_with_an_error, sample_comment_data_with_errors);
		
		//	12 - 4 = 8 
		
		//	4080 - 48 =	4032
		equal(data.mode, 4092);
		equal(data.error, 52);
		
		equal(data.data["100000416787478"][flags.FRIEND_POST_FLAG], 1);
		equal(data.data["100000416787478"][flags.MY_COMMENT_ON_NOTE_FLAG], 1);
		equal(data.data["100000416787478"][flags.MY_COMMENT_ON_PHOTO_FLAG], 1);
		equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_STATUS_FLAG], 1);
		equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_LINK_FLAG], 1);
		equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_NOTE_FLAG], 1);
		equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_PHOTO_FLAG], 1);

        equal(data.data["100000525262538"][flags.FRIEND_POST_FLAG], 2);
        equal(data.data["100000525262538"][flags.MY_COMMENT_ON_NOTE_FLAG], 2);
        equal(data.data["100000525262538"][flags.MY_COMMENT_ON_PHOTO_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_STATUS_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_LINK_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_NOTE_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_PHOTO_FLAG], 2);
	
		data = concat(sample_comment_data_with_errors, sample_message_comment_on_link_status_data_with_errors);
		
		equal(data.mode, 4083);
		equal(data.error, 32);
		
        equal(data.data["100000416787478"][flags.ONEWAY_MESSAGE_FLAG], 1);
        equal(data.data["100000416787478"][flags.TWOWAY_MESSAGE_FLAG], 1);
        equal(data.data["100000416787478"][flags.MY_COMMENT_ON_STATUS_FLAG], 1);
        equal(data.data["100000416787478"][flags.MY_COMMENT_ON_NOTE_FLAG], 1);
        equal(data.data["100000416787478"][flags.MY_COMMENT_ON_PHOTO_FLAG], 1);
        equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_STATUS_FLAG], 1);
        equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_LINK_FLAG], 1);
        equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_NOTE_FLAG], 1);
        equal(data.data["100000416787478"][flags.FRIEND_COMMENT_ON_PHOTO_FLAG], 1);

        equal(data.data["100000525262538"][flags.ONEWAY_MESSAGE_FLAG], 2);
        equal(data.data["100000525262538"][flags.TWOWAY_MESSAGE_FLAG], 2);
        equal(data.data["100000525262538"][flags.MY_COMMENT_ON_STATUS_FLAG], 2);
        equal(data.data["100000525262538"][flags.MY_COMMENT_ON_NOTE_FLAG], 2);
        equal(data.data["100000525262538"][flags.MY_COMMENT_ON_PHOTO_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_STATUS_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_LINK_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_NOTE_FLAG], 2);
        equal(data.data["100000525262538"][flags.FRIEND_COMMENT_ON_PHOTO_FLAG], 2);
		
	}catch(err){trace2(err);}
	
});

</script>
</head>
<body>
    <h1 id="qunit-header">QUnit Test Suite</h1>
    <h2 id="qunit-banner"></h2>
    <div id="qunit-testrunner-toolbar"></div>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
    <div id="qunit-fixture">test markup</div>
</body>
</html>